package org.hxyjs.controller;

import org.hxyjs.dto.DTO;
import org.hxyjs.entity.Cheforder;
import org.hxyjs.page.PageInfo;
import org.hxyjs.service.CheforderService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@CrossOrigin
@Controller //@Controller注解是用spring容器生成 对象 默认对象名 cheforderController
@RequestMapping("/cheforderController") //@RequestMapping 用户请求查找该资源使用的名字 网名 默认  /cheforderController
public class CheforderController {
	@Resource
     CheforderService cheforderService;
	@RequestMapping("/getAllCheforder")
	@ResponseBody //把方法的返回值按json转换之后 输出到浏览器
    public DTO<Cheforder> getAllCheforder() throws Exception{
    	System.out.println("查询管理员");
    	return cheforderService.getAllCheforders();
    }
	@RequestMapping("/addCheforder")
	@ResponseBody
	public DTO<Cheforder> addCheforder(@RequestBody Cheforder cheforder) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("增加管理员成功");
		return cheforderService.addCheforder(cheforder);
	}

	@RequestMapping("/deleteCheforderByCuno/{cuno}")
	@ResponseBody
    public DTO<Cheforder> deleteCheforderByCuno(@RequestBody @PathVariable("cuno") String cuno) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
    	System.out.println(cuno+"删除管理员成功");
    	return cheforderService.deleteCheforderByCuno(cuno);
    }



	@RequestMapping("/getCheforderByCuno/{cuno}")
	@ResponseBody
	public DTO<Cheforder> getCheforderByCuno(@PathVariable("cuno") String cuno) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println(cuno+"根据主键查询管理员成功");
		return cheforderService.getCheforderByCuno(cuno);
	}

	@RequestMapping("/updateCheforderByCuno")
	@ResponseBody
	public DTO<Cheforder> updateCheforderByCuno(@RequestBody Cheforder cheforder) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("修改管理员成功");
		System.out.println(cheforder);
		return cheforderService.updateCheforderByCuno(cheforder);
	}

	@RequestMapping("/getCheforderByPage")
	@ResponseBody
	public DTO<Cheforder> getCheforderByPage(PageInfo pageInfo) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("分页查询管理员成功");
		return cheforderService.getCheforderByPage(pageInfo);
	}

}
